from GraphSettings.GraphFeatures.ColorStyle import ColorStyle;
from PyQt4 import QtCore, QtGui;

class NodeView():
    class InfoStyle(): 
        fullInfo, compactR, compactV, compactD = range(4);
        onlyR, onlyV, onlyD, onlyStDim, noneInfo = range(4,9);
    class StatusStyle():
        normal, current, forbidden, goal = range(4);
    class BkgColorVal():
        none, value, reward, stateDim, distance = range(5);
    
    def __init__(self, objNode):
        self.nodeModel = objNode.nodeModel;
        self.objNode = objNode;
        self.nodeStyleStatus = 0;
        self.bkgStyle, self.bkgDim = 0, 0;
        self.bkgMaxVal = 0;
        self.bkgMinVal = 0;
        self.bHideWalls = True;
        self.colorStyle = ColorStyle();
        
    def createNodeView(self):
        self.createStateShape();
        self.createTexts();
        self.setStyleStatus(self.nodeModel.StateType);
#         self.setTooltip(self.nodeModel.Persons);
        self.tPersons = self.nodeModel.Persons;
#         self.setTooltip(self.nodeModel.TxtStateId);
        self.setMovable(True);
        self.setSelectable(True);
        self.setPressedStyle(False);
    
    []#Give Outline Node Position for In-Edges    
    def getNodeRegion(self): 
        return self.qStateItem.path();
    
    def getBoundingRect(self):
        return self.qStateItem.boundingRect();
   
    []#Creating the State Shape & Text Items        
    def createStateShape(self):
#        nX, nY, nWidth, nHeight = 10,10, 100,100;
        nX, nY, nWidth, nHeight = 0,0, 150,150;
        self.nCenterPt = QtCore.QPointF((nWidth-nX)/2.0, (nHeight-nY)/2.0);
        self.qRect = QtCore.QRectF(nX,nY, nWidth,nHeight);
        qPath = QtGui.QPainterPath();
        qPath.addRoundedRect(self.qRect, 15,15);
        self.qStateItem = QtGui.QGraphicsPathItem(qPath, self.objNode);
        self.qStateItem.setBrush(QtGui.QBrush(QtGui.QColor(255,255,255, 255)));
#         self.createWalls();
        
    def createWalls(self):
        self.initWallsArray();
        wS, wBrush = 8, QtGui.QBrush(QtGui.QColor(0,0,0, 255));
        wPen = QtGui.QPen(QtGui.QColor(0,0,0, 255), 2);
        nX, nY = self.qRect.x(), self.qRect.y();
        nWidth, nHeight = self.qRect.width(), self.qRect.height();
        #Left
        qPathL = QtGui.QPainterPath(); 
        qPathL.addRect(QtCore.QRectF(nX,nY, wS,nHeight));
        self.qWallL = QtGui.QGraphicsPathItem(qPathL, self.objNode);
        self.qWallL.setBrush(wBrush);
        self.qWallL.setPen(wPen);
        #Right
        qPathR = QtGui.QPainterPath(); 
        qPathR.addRect(QtCore.QRectF(nX+nWidth-wS,nY, wS,nHeight));
        self.qWallR = QtGui.QGraphicsPathItem(qPathR, self.objNode);
        self.qWallR.setBrush(wBrush);
        self.qWallR.setPen(wPen);
        #Top
        qPathT = QtGui.QPainterPath(); 
        qPathT.addRect(QtCore.QRectF(nX,nY, nWidth,wS));
        self.qWallT = QtGui.QGraphicsPathItem(qPathT, self.objNode);
        self.qWallT.setBrush(wBrush);
        self.qWallT.setPen(wPen);
        #Bottom
        qPathB = QtGui.QPainterPath(); 
        qPathB.addRect(QtCore.QRectF(nX,nY+nWidth-wS, nWidth,wS));
        self.qWallB = QtGui.QGraphicsPathItem(qPathB, self.objNode);
        self.qWallB.setBrush(wBrush);
        self.qWallB.setPen(wPen);
        #Array of Walls
        self.aWalls = [];
        self.aWalls.append(self.qWallL);
        self.aWalls.append(self.qWallT);
        self.aWalls.append(self.qWallR);
        self.aWalls.append(self.qWallB);
        self.hideWalls();
        
    def hideWalls(self):
        for qWall in self.aWalls:
            qWall.setVisible(False);
        
    def setClickWalls(self, pos):
        pass;
#         pos = self.objNode.mapFromScene(pos);
#         for qWall in self.aWalls:
#             if qWall.boundingRect().contains(pos):
#                 qWall.setVisible(not qWall.isVisible());
        
    def getTypeWalls(self):
        pass;
#         bW = [];
#         for qWall in self.aWalls:
#             bW.append(qWall.isVisible());
#         iWall = self.aTypeWalls.index(bW)+1;
#         return iWall;
    
    def createTexts(self):
        self.createTxtGrpId();
        self.createTxtActivity();
        self.createTxtRole();
        self.createTxtFrmRng();
#         self.createTxtStateId();
#         self.createTxtStateDim();
#         self.createTxtReward();
#         self.createTxtValue();
#         self.createTxtDistance();
        
    def createTxtGrpId(self):
        self.qTxtGrpId = QtGui.QGraphicsTextItem(self.objNode);
        self.posGrpId = QtCore.QPointF(self.qRect.x()+25,self.qRect.y()+15);
        self.qTxtGrpId.setPos(self.posGrpId);
        self.setTxtGrpId(self.nodeModel.TxtGrpId);
        self.qTxtGrpId.setDefaultTextColor(QtGui.QColor(0,0,0, 150));
        self.qTxtGrpId.setFont(QtGui.QFont("Arial", 14, QtGui.QFont.Bold));
    
    def createTxtActivity(self):
        self.qTxtAct = QtGui.QGraphicsTextItem(self.objNode);
        self.posAct = QtCore.QPointF(self.qRect.x(),self.qRect.y()+60);
        self.qTxtAct.setPos(self.posAct);
        self.qTxtAct.setTextWidth(self.qRect.width());
        self.setTxtActivity(self.nodeModel.TxtAct);
        self.qTxtAct.setDefaultTextColor(QtGui.QColor(0,0,0, 255));
        self.qTxtAct.setFont(QtGui.QFont("Arial", 10, QtGui.QFont.Bold));
    
    def createTxtRole(self):
        self.qTxtRole = QtGui.QGraphicsTextItem(self.objNode);
        self.posRole = QtCore.QPointF(self.qRect.x(), self.qRect.height()-45);
        self.qTxtRole.setPos(self.posRole);
        self.qTxtRole.setTextWidth(self.qRect.width());
        self.setTxtRole(self.nodeModel.TxtRole);
        self.qTxtRole.setDefaultTextColor(QtGui.QColor(0,0,0, 255));
        self.qTxtRole.setFont(QtGui.QFont("Arial", 8));
    
    def createTxtFrmRng(self):
        self.qTxtFrmRng = QtGui.QGraphicsTextItem(self.objNode);
        self.posFrmRng = QtCore.QPointF(self.qRect.x(), self.qRect.height()-30)
        self.qTxtFrmRng.setPos(self.posFrmRng);
        self.qTxtFrmRng.setTextWidth(self.qRect.width());
        self.setTxtFrmRng(self.nodeModel.TxtFrmRng);
        self.qTxtFrmRng.setDefaultTextColor(QtGui.QColor(0,80,0, 255));
        self.qTxtFrmRng.setFont(QtGui.QFont("Arial", 9, QtGui.QFont.DemiBold));
    
    def setTxtGrpId(self, tGrpId):
        tAlign = "<div align='center'>";
        self.qTxtGrpId.setHtml(tAlign + tGrpId + "</div>");
        self.tGrpId = tGrpId;
    
    def setTxtActivity(self, tAct):
        tAlign = "<div align='center'>";
        self.qTxtAct.setHtml(tAlign + tAct + "</div>");
        self.tAct = tAct;
        self.setStyleStatus_Normal();
    
    def setTxtRole(self, tRole):
        tAlign = "<div align='center'>";
        self.qTxtRole.setHtml(tAlign + tRole + "</div>");
        self.tRole = tRole;
    
    def setTxtFrmRng(self, tFrmRng):
        tAlign = "<div align='center'>";
        self.qTxtFrmRng.setHtml(tAlign + tFrmRng + "</div>");
        self.tFrmRng = tFrmRng;
        
    def createTxtStateId(self):
        self.qTxtStId = QtGui.QGraphicsTextItem(self.objNode);
        self.posStId = QtCore.QPointF(self.qRect.x()+25,self.qRect.y()+15);
        self.qTxtStId.setPos(self.posStId);
        self.setTxtStateId(self.nodeModel.TxtStateId);
        self.qTxtStId.setDefaultTextColor(QtGui.QColor(0,0,0, 150));
        self.qTxtStId.setFont(QtGui.QFont("Arial", 12, QtGui.QFont.Bold));        
        
    def createTxtStateDim(self):
        self.qTxtStDim = QtGui.QGraphicsTextItem(self.objNode);
        self.posStDim = QtCore.QPointF(self.qRect.x(),self.qRect.y()+47);
        self.qTxtStDim.setPos(self.posStDim);
        self.qTxtStDim.setTextWidth(self.qRect.width());
        self.setTxtStateDim(self.nodeModel.StateDim);
        self.qTxtStDim.setDefaultTextColor(QtGui.QColor(0,0,0, 255));
        self.qTxtStDim.setFont(QtGui.QFont("Arial", 10, QtGui.QFont.Bold));
    
    def createTxtReward(self):
        self.qTxtReward = QtGui.QGraphicsTextItem(self.objNode);
        self.posR = QtCore.QPointF(self.qRect.x()+5, self.qRect.height()-55)
        self.qTxtReward.setPos(self.posR);
        self.qTxtReward.setTextWidth(60);
        self.setTxtReward(self.nodeModel.nReward);
        self.qTxtReward.setDefaultTextColor(QtGui.QColor(0,80,0, 255));
        self.qTxtReward.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.DemiBold));
    
    def createTxtValue(self):
        self.qTxtValue = QtGui.QGraphicsTextItem(self.objNode);
        self.posV = QtCore.QPointF(self.qRect.width()-65, self.qRect.height()-55)
        self.qTxtValue.setPos(self.posV);
        self.qTxtValue.setTextWidth(60);
        self.setTxtValue(self.nodeModel.nValue);
        self.qTxtValue.setDefaultTextColor(QtGui.QColor(0,80,0, 255));
        self.qTxtValue.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.DemiBold));
    
    def createTxtDistance(self):
        self.qTxtDistance = QtGui.QGraphicsTextItem(self.objNode);
        self.posD = QtCore.QPointF(self.qRect.width()-65, self.qRect.y()+15);
        self.qTxtDistance.setPos(self.posD);
        self.qTxtDistance.setTextWidth(60);
        self.setTxtDistance(self.nodeModel.nDistance);
        self.qTxtDistance.setDefaultTextColor(QtGui.QColor(0,80,0, 255));
        self.qTxtDistance.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.DemiBold));
        
    def setTxtStateId(self, tStId):
        tAlign = "<div align='center'>";
        self.qTxtStId.setHtml(tAlign + tStId + "</div>");
        self.tStId = tStId;
        
    def setTxtStateDim(self, aStateDim):
        tAlign = "<div align='center'>";
        txtStDim = "State<br>";
        i = 0;
        for j in range(len(aStateDim)): #@UnusedVariable
            if i < len(aStateDim):
                txtStDim += str(aStateDim[i]);
            if i+1 < len(aStateDim):
                i+=1;
                txtStDim += ", " + str(aStateDim[i]);
            if i+2 < len(aStateDim):
                i+=1;
                txtStDim += ", " + str(aStateDim[i]);
            txtStDim += "<br>";
            i+=1;
        self.qTxtStDim.setHtml(tAlign + txtStDim + "</div>");
        self.tStateDim = aStateDim;
        if len(aStateDim) > 0:
            self.updateStWalls();
        self.setBkgColor_ByVal(self.bkgStyle, self.bkgMaxVal, self.bkgMinVal, self.bkgDim);
        
    def setTxtReward(self, tReward):
        tAlign = "<div align='center'>";
        self.qTxtReward.setHtml(tAlign + "R<br>" + str(tReward) + "</div>");
        self.tReward = tReward;
        self.setBkgColor_ByVal(self.bkgStyle, self.bkgMaxVal, self.bkgMinVal, self.bkgDim);
        
    def setTxtValue(self, tValue):
        tAlign = "<div align='center'>";
        self.qTxtValue.setHtml(tAlign + "V<br>" + str(tValue) + "</div>");
        self.tValue = tValue;
        self.setBkgColor_ByVal(self.bkgStyle, self.bkgMaxVal, self.bkgMinVal, self.bkgDim);
        
    def setTxtDistance(self, tDistance):
        tAlign = "<div align='center'>";
        self.qTxtDistance.setHtml(tAlign + "D<br>" + str(tDistance) + "</div>");
        self.tDistance = tDistance;
        self.setBkgColor_ByVal(self.bkgStyle, self.bkgMaxVal, 0, self.bkgDim);
        
    def refreshStateTxts(self):
        if self.tGrpId != self.nodeModel.TxtGrpId:
            self.setTxtGrpId(self.nodeModel.TxtGrpId);
        if self.tAct != self.nodeModel.TxtAct:
            self.setTxtActivity(self.nodeModel.TxtAct);
        if self.tRole != self.nodeModel.TxtRole:
            self.setTxtRole(self.nodeModel.TxtRole);
        if self.tFrmRng != self.nodeModel.TxtFrmRng:
            self.setTxtFrmRng(self.nodeModel.TxtFrmRng);
        if self.tPersons != self.nodeModel.Persons:
            self.setTooltip(self.nodeModel.Persons);
            self.tPersons = self.nodeModel.Persons;
#         if self.tStId != self.nodeModel.TxtStateId:
#             self.setTxtStateId(self.nodeModel.TxtStateId);
#         if self.tStateDim != self.nodeModel.StateDim:
#             self.setTxtStateDim(self.nodeModel.StateDim);
#         if self.tReward != self.nodeModel.nReward:
#             self.setTxtReward(self.nodeModel.nReward);
#         if self.tValue != self.nodeModel.nValue:
#             self.setTxtValue(self.nodeModel.nValue);
#         if self.tDistance != self.nodeModel.nDistance:
#             self.setTxtDistance(self.nodeModel.nDistance);
#         if self.nodeStyleStatus != self.nodeModel.nStateType:
#             self.setStyleStatus(self.nodeModel.nStateType);
            
    def initWallsArray(self):
        self.aTypeWalls = [];
        self.aTypeWalls.append([True, False, False, False]); #1
        self.aTypeWalls.append([False, True, False, False]); #2
        self.aTypeWalls.append([False, False, True, False]); #3
        self.aTypeWalls.append([False, False, False, True]); #4
        self.aTypeWalls.append([True, True, False, False]); #5
        self.aTypeWalls.append([False, True, True, False]); #6
        self.aTypeWalls.append([False, False, True, True]); #7
        self.aTypeWalls.append([True, False, False, True]); #8
        self.aTypeWalls.append([True, True, True, False]); #9
        self.aTypeWalls.append([False, True, True, True]); #10
        self.aTypeWalls.append([True, False, True, True]); #11
        self.aTypeWalls.append([True, True, False, True]); #12
        self.aTypeWalls.append([True, False, True, False]); #13
        self.aTypeWalls.append([False, True, False, True]); #14
        self.aTypeWalls.append([False, False, False, False]); #15
        self.aTypeWalls.append([True, True, True, True]); #16
            
    def updateStWalls(self):
        pass;
#         self.hideWalls();
#         if self.bHideWalls: return;
#         iTypeW = int(self.nodeModel.StateDim[0])-1;
#         if iTypeW > len(self.aTypeWalls) or iTypeW < 0: return;
#         for i in range(len(self.aWalls)):
#             self.aWalls[i].setVisible(self.aTypeWalls[iTypeW][i]);
        
    def setSelectedStyle(self, bSelected):
        if bSelected:
            self.qStateItem.setPen(QtGui.QPen(QtGui.QColor(0,0,255, 255), 4));
        else:
            self.setStyleStatus(self.nodeStyleStatus);
            
    def setPressedStyle(self, bPressed):
        self.setCursor(bPressed);
            
    def setCursor(self, bClosedHandCursor):
        pass;
#        if bClosedHandCursor:            
#            self.objNode.setCursor(QtCore.Qt.ClosedHandCursor);
#        else:
#            self.objNode.setCursor(QtCore.Qt.OpenHandCursor);
            
    def setSelectable(self, bSelectable):
        self.objNode.setFlag(QtGui.QGraphicsItem.ItemIsSelectable, bSelectable);
            
    def setMovable(self, bMovable):
        self.objNode.setFlag(QtGui.QGraphicsItem.ItemIsMovable, bMovable);
        
    def setTooltip(self, sTooltip):
        self.objNode.setToolTip(sTooltip);

    def setStyleInfo(self, nStyleInfo):
        infoStyle = NodeView.InfoStyle;
        if nStyleInfo == infoStyle.fullInfo:
            self.setStyle_FullInfo();
        elif nStyleInfo == infoStyle.compactR:
            self.setStyle_CompactR();
        elif nStyleInfo == infoStyle.compactV:
            self.setStyle_CompactV();
        elif nStyleInfo == infoStyle.compactD:
            self.setStyle_CompactD();
        elif nStyleInfo == infoStyle.onlyR:
            self.setStyle_OnlyR();
        elif nStyleInfo == infoStyle.onlyV:
            self.setStyle_OnlyV();
        elif nStyleInfo == infoStyle.onlyD:
            self.setStyle_OnlyD();
        elif nStyleInfo == infoStyle.onlyStDim:
            self.setStyle_OnlyStDim();
        elif nStyleInfo == infoStyle.noneInfo:
            self.setStyle_NoneInfo();
        
    def setStyle_FullInfo(self):
        #State Dim
        self.qTxtStDim.setPos(self.posStDim);
        self.qTxtStDim.setFont(QtGui.QFont("Arial", 10, QtGui.QFont.Bold));
        self.qTxtStDim.setVisible(True);
        #Reward
        self.qTxtReward.setPos(self.posR);
        self.qTxtReward.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.DemiBold));
        self.qTxtReward.setVisible(True);
        #Value
        self.qTxtValue.setPos(self.posV);
        self.qTxtValue.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.DemiBold));
        self.qTxtValue.setVisible(True);
        #Distance
        self.qTxtDistance.setPos(self.posD);
        self.qTxtDistance.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.DemiBold));
        self.qTxtDistance.setVisible(True);
        
    def setStyle_CompactR(self):
        #State Dim
        self.qTxtStDim.setPos(self.posStDim);
        self.qTxtStDim.setFont(QtGui.QFont("Arial", 10, QtGui.QFont.Bold));
        self.qTxtStDim.setVisible(True);
        #Reward
        self.qTxtReward.setPos(self.posR);
        self.qTxtReward.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.DemiBold));
        self.qTxtReward.setVisible(True);
        #Value
        self.qTxtValue.setVisible(False);
        #Distance
        self.qTxtDistance.setVisible(False);
        
    def setStyle_CompactV(self):
        #State Dim
        self.qTxtStDim.setPos(self.posStDim);
        self.qTxtStDim.setFont(QtGui.QFont("Arial", 10, QtGui.QFont.Bold));
        self.qTxtStDim.setVisible(True);
        #Reward
        self.qTxtReward.setVisible(False);
        #Value
        self.qTxtValue.setPos(self.posV);
        self.qTxtValue.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.DemiBold));
        self.qTxtValue.setVisible(True);
        #Distance
        self.qTxtDistance.setVisible(False);
        
    def setStyle_CompactD(self):
        #State Dim
        self.qTxtStDim.setPos(self.posStDim);
        self.qTxtStDim.setFont(QtGui.QFont("Arial", 10, QtGui.QFont.Bold));
        self.qTxtStDim.setVisible(True);
        #Reward
        self.qTxtReward.setVisible(False);
        #Value
        self.qTxtValue.setVisible(False);
        #Distance
        self.qTxtDistance.setPos(self.posD);
        self.qTxtDistance.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.DemiBold));
        self.qTxtDistance.setVisible(True);
        
    def setStyle_OnlyR(self):
        #State Dim
        self.qTxtStDim.setVisible(False);
        #Reward
        pos = QtCore.QPointF(self.qRect.x()+45,self.qRect.y()+50);
        self.qTxtReward.setPos(pos);
        self.qTxtReward.setFont(QtGui.QFont("Arial", 13, QtGui.QFont.Bold));
        self.qTxtReward.setVisible(True);
        #Value
        self.qTxtValue.setVisible(False);
        #Distance
        self.qTxtDistance.setVisible(False);
        
    def setStyle_OnlyV(self):
        #State Dim
        self.qTxtStDim.setVisible(False);
        #Reward
        self.qTxtReward.setVisible(False);
        #Value
        pos = QtCore.QPointF(self.qRect.x()+45,self.qRect.y()+45);
        self.qTxtValue.setPos(pos);
        self.qTxtValue.setFont(QtGui.QFont("Arial", 15, QtGui.QFont.Bold));
        self.qTxtValue.setVisible(True);
        #Distance
        self.qTxtDistance.setVisible(False);
        
    def setStyle_OnlyD(self):
        #State Dim
        self.qTxtStDim.setVisible(False);
        #Reward
        self.qTxtReward.setVisible(False);
        #Value
        self.qTxtValue.setVisible(False);
        #Distance
        pos = QtCore.QPointF(self.qRect.x()+45,self.qRect.y()+50);
        self.qTxtDistance.setPos(pos);
        self.qTxtDistance.setFont(QtGui.QFont("Arial", 13, QtGui.QFont.Bold));
        self.qTxtDistance.setVisible(True);
        
    def setStyle_OnlyStDim(self):
        #State Dim
        self.qTxtStDim.setPos(self.posStDim);
#        self.qTxtStDim.setFont(QtGui.QFont("Arial", 12, QtGui.QFont.Bold));
        self.qTxtStDim.setVisible(True);
        #Reward
        self.qTxtReward.setVisible(False);
        #Value
        self.qTxtValue.setVisible(False);
        #Distance
        self.qTxtDistance.setVisible(False);
        
    def setStyle_NoneInfo(self):
        #State Dim
        self.qTxtStDim.setVisible(False);
        #Reward
        self.qTxtReward.setVisible(False);
        #Value
        self.qTxtValue.setVisible(False);
        #Distance
        self.qTxtDistance.setVisible(False);
        
    def setActionsVisible(self, bVisible):
        for action in self.objNode.actions:
            action.actView.setVisible(bVisible);
            
    def setNodeStyle(self, nStyle=0):
        if nStyle == 0:
            nMove = 50;
            self.objNode.actions[0].setPos(150-nMove,75);
            self.objNode.actions[1].setPos(75,150-nMove);
            self.objNode.actions[2].setPos(nMove,75);
            self.objNode.actions[3].setPos(75,nMove);
        elif nStyle == 1:
            nMove = 50;
            self.objNode.actions[0].setPos(150,75);
            self.objNode.actions[1].setPos(75,150);
            self.objNode.actions[2].setPos(0,75);
            self.objNode.actions[3].setPos(75,0);
            
    def setStyleStatus(self, nStyleStatus):
        self.nodeStyleStatus = nStyleStatus;
        styleStatus = NodeView.StatusStyle;
        if nStyleStatus == styleStatus.normal:
            self.setStyleStatus_Normal();
        elif nStyleStatus == styleStatus.current:
            self.setStyleStatus_Current();
        elif nStyleStatus == styleStatus.forbidden:
            self.setStyleStatus_Forbidden();
        elif nStyleStatus == styleStatus.goal:
            self.setStyleStatus_Goal();
        #Restore any Dynamic Bkg color value style
        if self.bkgStyle != NodeView.BkgColorVal.none:
            self.setBkgColor_ByVal(self.bkgStyle, self.bkgMaxVal, self.bkgMinVal, self.bkgDim);
            
            
    def setStyleStatus_Normal(self):
        nC = 225 if self.tAct in ["WALK", "STAND", "RUN"] else 255;
        self.qStateItem.setPen(QtGui.QPen(QtGui.QColor(0,0,0, 255), 2));
        self.qStateItem.setBrush(QtGui.QBrush(QtGui.QColor(nC,nC,nC, 255)));
    
    def setStyleStatus_Current(self):
        nC = 225 if self.tAct in ["WALK", "STAND", "RUN"] else 255;
        self.qStateItem.setPen(QtGui.QPen(QtGui.QColor(0,0,0, 255), 8));
        self.qStateItem.setBrush(QtGui.QBrush(QtGui.QColor(nC,nC,nC, 255)));
    
    def setStyleStatus_Forbidden(self):
        self.qStateItem.setPen(QtGui.QPen(QtGui.QColor(255,0,0, 255), 4));
        self.qStateItem.setBrush(QtGui.QBrush(QtGui.QColor(255,200,200, 255)));
    
    def setStyleStatus_Goal(self):
        self.qStateItem.setPen(QtGui.QPen(QtGui.QColor(0,255,0, 255), 4));
        self.qStateItem.setBrush(QtGui.QBrush(QtGui.QColor(200,255,200, 255)));
        
#     def setStyleStatus_PhysAct(self):
#         self.qStateItem.setPen(QtGui.QPen(QtGui.QColor(0,0,0, 255), 2));
#         self.qStateItem.setBrush(QtGui.QBrush(QtGui.QColor(225,225,225, 255)));        
        
    def setBkgColor_ByVal(self, nValType, nMaxVal=1, nMinVal=0, nStDim=0):
        self.bkgStyle = nValType;
        self.bkgMaxVal = float(nMaxVal);
        self.bkgMinVal = float(nMinVal);
        iOpc = 0;
        if nValType == NodeView.BkgColorVal.value:
            k = self.nodeModel.Value;
            iOpc = 2;
        elif nValType == NodeView.BkgColorVal.reward:
            k = self.nodeModel.Reward;
            iOpc = 1;
        elif nValType == NodeView.BkgColorVal.distance:
            k = self.nodeModel.Distance;
            iOpc = 4;
        elif nValType == NodeView.BkgColorVal.stateDim:
            self.bkgDim = nStDim;
            k = float(self.nodeModel.StateDim[nStDim]);
            iOpc = 2;
        elif nValType == NodeView.BkgColorVal.none:
            self.setStyleStatus(self.nodeStyleStatus);
            return;
        k = (k - self.bkgMinVal)/self.bkgMaxVal;
        color = self.colorStyle.getColorStyle(iOpc, k);
        self.qStateItem.setBrush(QtGui.QBrush(color));
    
    def setStateShape(self, kCorners):
        qPath = QtGui.QPainterPath();
        #Can also be any other shape...
        if kCorners==0:
            qPath.addRect(self.qRect);
        elif kCorners>80:
            qPath.addEllipse(self.qRect);
        else:
            qPath.addRoundedRect(self.qRect, kCorners,kCorners);
        self.qStateItem.setPath(qPath);
        
        
